package com.rerun.phone.memberuser;

import com.rerun.common.anno.ResponseExceptionReturn;
import com.rerun.common.bean.Rest;
import com.rerun.entity.HaveSkills;
import com.rerun.service.ISkillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * The type Skills controller.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /10/19 16:36
 */
@Api(value = "求职端-技能特长", description = "求职端-技能特长")
@RestController
@RequestMapping("/memberApi/skills")
public class SkillsController {

    @Resource
    private ISkillService iSkillService;

    /**
     * Add rest.
     *
     * @param memberId  the member id
     * @param skillName the skill name
     * @return the rest
     */
    @ApiOperation(value = "添加技能特长", httpMethod = "POST", response = Rest.class, notes = "添加技能特长")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest add(@RequestParam String memberId,@RequestParam String skillName) {
        HaveSkills skills = new HaveSkills();
        skills.setMemberId(memberId);
        skills.setSkillName(skillName);
        skills.setCreateTime(new Date());
        boolean flag = iSkillService.insert(skills);
        return flag ? Rest.ok() : Rest.failure("add failure");
    }

    /**
     * Update rest.
     *
     * @param id        the id
     * @param skillName the skill name
     * @param memberId  the member id
     * @return the rest
     */
    @ApiOperation(value = "修改技能特长", httpMethod = "POST", response = Rest.class, notes = "修改技能特长")
    @RequestMapping(value = "/edit/{id}", method = RequestMethod.POST)
   @ResponseExceptionReturn
    public Rest update(  @PathVariable("id") String id,@RequestParam String skillName,@RequestParam String memberId) {
        HaveSkills skills = new HaveSkills();
        skills.setId(id);
        skills.setMemberId(memberId);
        skills.setSkillName(skillName);
        skills.setUpdateTime(new Date());
        boolean flag = iSkillService.updateById(skills);
        return flag ? Rest.ok() : Rest.failure("update failure");
    }

    /**
     * 通过技能特长ID删除技能特长.
     *
     * @param id the id
     * @return the rest
     */
    @ApiOperation(value = "通过技能特长ID删除技能特长", httpMethod = "POST", response = Rest.class, notes = "通过技能特长ID删除技能特长")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest deleteById(@PathVariable("id") String id) {
        boolean flag = iSkillService.deleteById(id);
        return flag ? Rest.ok() : Rest.failure("delete failure");
    }
}
